// pages/shopping/paySuccess/paySuccess.js
var app = getApp();
var flowContract = app.globalData._network_path + 'flowContract.png';
var authInfo= { 'status_name': '待认证', status: '' };
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_id:'',//用户id
    is_auth:1,//是否认证
    order_type: '',//订单类型，1：租赁，2：购买
    flowContract: flowContract,
    order_id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      order_id: options.order_id
    })
    that.getUserInfo();
    that.getOrderInfo();
    that.getAuthInfo();

    //判断页面栈里面的页面数是否大于2
    if (getCurrentPages().length > 2) {
      //获取页面栈
      let pages = getCurrentPages()
      //给上一个页面设置状态
      let curPage = pages[pages.length - 2];
      let data = curPage.data;
      curPage.setData({ 'isBack': true });
    }
  },

  
  //预约安装时间
  installTime:function(e){
    var that=this;
//    app.saveFormId(e.detail.formId);
    var is_auth = that.data.is_auth;
    var order_id = that.data.order_id;
    var url = '../../user/appointment/appointment?order_id=' + order_id;
    
    wx.navigateTo({
      url: url,
    })
  },
  //获取用户信息
  getUserInfo:function(){
    var that = this;
    app.ajax({
      url: 'User/User/getUserInfo',
      method: "POST",
      data: { },
      success: function (res) {
        //console.log(res)
        if (res.data.code == 1000) {
          var is_auth = res.data.data.is_auth;
          //console.log(is_auth);
          that.setData({
            is_auth: is_auth
          })
        } else {
          app.showToast(res.data.message);
        }
      }
    })
  },
  //返回商城
  returnBack: function(){
    wx.switchTab({
      url: '../shoppingHome/shoppingHome',
    })
  },
  //查看订单
  goDetail: function(){
    var that = this;
    wx.navigateTo({
      url: '../../user/myOrderDetail/myOrderDetail?order_id=' + that.data.order_id,
    })
  },
  //查询订单详情
  getOrderInfo: function () {
    var that = this;
    var order_id = that.data.order_id;
    app.ajax({
      url: 'User/Order/getOrderDetail',
      method: "POST",
      data: { order_id: order_id },
      success: function (res) {
        //console.log(res)
        if (res.data.code == 1000) {
          that.setData({
            order_type: res.data.data.order_type
          });
        } else {
          app.showToast(res.data.message);
        }
      }
    })
  },
  // 查看流程大图
  viewPicture(e) {
    var url = e.currentTarget.dataset.url;
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: [url] // 需要预览的图片http链接列表
    })
  },
  //跳转我的认证
  goRealname() {
    var that = this;
    if (authInfo.status == -2) {
      wx.navigateTo({ //../../shopping/uploadDocuments/uploadDocuments
        url: '../../shopping/uploadDocuments/uploadDocuments',
      })
    } else if (authInfo.status == -3) {
      wx.navigateTo({
        url: '../../shopping/faceRecognition/faceRecognition',
      })
    } else if (authInfo.status == 2 || authInfo.status == 1) {
      wx.navigateTo({
        url: '../../myCertification/myCertification',
      })
    } else {
      wx.navigateTo({
        url: '../../shopping/realName/realName',
      })
    }

  },
  //获取用户认证信息
  getAuthInfo() {
    var that = this;
    app.ajax({
      url: "User/Realname/getAuthInfo",
      data: {},
      success: function (res) {
        if (res.data.code == 1000) {
            authInfo= res.data.data
        
        } else {
          authInfo ={ 'status_name': '待认证', 'status': '' }
        }
      }
    })
  }

})